﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.MachineSys.PublicModel
{
    public partial class SPapersRemindList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "SPapersRemindList";
            }
        }

        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "ExpiryDate" : base.orderField; ;
            }
        }

        protected string YearCarefulDateFrom
        {
            get
            {
                return GetRequestValue<string>("YearCarefulDateFrom","");
            }
        }
        protected string YearCarefulDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(YearCarefulDateFrom))
                    return "";
                string dend = GetRequestValue<string>("YearCarefulDateTo", "");
                if (string.IsNullOrEmpty(dend))
                    return Convert.ToDateTime(YearCarefulDateFrom).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
                else
                    return GetRequestValue<string>("YearCarefulDateTo", "");
            }
        }

        protected string IDNO
        {
            get
            {
                return GetRequestValue<string>("IDNO", "");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
        protected DataTable SUMDT = null;
        protected void DataBind()
        {
            //  string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
            DataTable DTC = SPapersRemindController.GetPagination(GetSQLWhere(), pageNum,numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataSource = DTC;
            this.rpMenu.DataBind();

            
        }

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if(!string.IsNullOrEmpty(YearCarefulDateFrom))
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("YearCarefulDate", QueryOperatorsEnum.范围, YearCarefulDateFrom + "|" + YearCarefulDateTo);
            
            wheresql = sqlcommonFiled;
            string ItemNameSql = "";
            if (!string.IsNullOrEmpty(IDNO))
            {
                ItemNameSql = QueryOperatorsEnumHelper.ConvertCommonOperator("IDNO", QueryOperatorsEnum.包含, IDNO);
                if (wheresql == "")
                    wheresql = ItemNameSql;
                else
                    wheresql = wheresql + " and " + ItemNameSql;
            }

            if (!User.IsSuperAdmin)
            {
                ItemNameSql = QueryOperatorsEnumHelper.ConvertCommonOperator("CreateUserId", QueryOperatorsEnum.等于, User.UserId.ToString());
                if (wheresql == "")
                    wheresql = ItemNameSql;
                else
                    wheresql = wheresql + " and " + ItemNameSql;
            }
            
            return wheresql;
        }

        protected string GetYearCarefulUrl(object YearCarefulDate,object id)
        { 
            string url="<a style=\"color:Red; font-weight:bold;\" href=\"PublicModel/SPapersRemindEdit.aspx?ID={0}\" rel=\"SPapersRemindEdit\" target=\"dialog\" title=\"证件年审\" max=false  mask=true  maxable=false  minable=false  resizable=false drawable=true  width=\"820\" height=\"320\" >待年审</a>";
            if(Convert.ToDateTime(YearCarefulDate)<=DateTime.Now && HasPower(Permission.修改))
            {
                return string.Format(url,id);
            }
            else
                return "";
        }
    }
}